package handler

import (
	"github.com/gin-gonic/gin"
	"zy12/model"
	"zy12/reporsitory"
	"zy12/request"
	"zy12/response"
)

func Comment(c *gin.Context) {
	var req request.AddComment
	err := c.ShouldBind(&req)
	if err != nil {
		response.ResponseError(c, "错误", err.Error())
		return
	}
	userId := c.GetUint("userId")
	comment := model.Comment{
		UserId:   int(userId),
		ParentId: req.ParentId,
		Content:  req.Content,
	}
	reporsitory.Create(&comment)
	if comment.Id == 0 {
		response.ResponseError(c, "添加评论失败", nil)
	}
	response.ResponseSuccess(c, "添加评论成功", comment)
}
